package action.common;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import dao.common.*;
import model.common.Employee;

public class EmployeeAction {

	private Employee employee;

	public void add(Employee employee) throws Exception{
		EmployeeDao dao=new EmployeeDao();
		dao.addEmployee(employee);
	}
	
	public void get(Integer employeeId) throws Exception{
		EmployeeDao dao=new EmployeeDao();
		dao.get(employeeId);
	}
	
	public void edit(Employee employee) throws SQLException{
		EmployeeDao dao=new EmployeeDao();
		dao.updateEmployee(employee);
	}
	
	public void del(Integer employeeId) throws SQLException{
		EmployeeDao dao=new EmployeeDao();
		dao.deleteEmployee(employeeId);
	}
	
	public List<Employee> query(List<Map<String, Object>> params) throws Exception{
		EmployeeDao dao=new EmployeeDao();
		
		return dao.query(params);
		
	}
	
	public List<Employee> query(String employeeName,String employeePassword) throws Exception{
		EmployeeDao dao=new EmployeeDao();
		return dao.query(employeeName, employeePassword);
		
	}
	
	public Boolean login(Employee e){
		EmployeeDao dao=new EmployeeDao();
		Employee em=dao.getLoginEmployeeName(e.getEmployeeName());
		
		if (em != null) {
			if ((em.getEmployeePassword()).equals(e.getEmployeePassword())){
				e.setEmployeeId(em.getEmployeeId());
				e.setEmployeeAddress(em.getEmployeeAddress());
				e.setEmployeeAge(em.getEmployeeAge());
				e.setEmployeeEmail(em.getEmployeeEmail());
				e.setEmployeeIdentifyId(em.getEmployeeIdentifyId());
				e.setEmployeeSex(em.getEmployeeSex());
				e.setEmployeeTelephone(em.getEmployeeTelephone());
				return true;
			}
			else
				return false;
		} else
			return false;
	}
}
